package evs.brp;

import java.io.Serializable;
import java.util.Vector;

public class Message implements Serializable {
	
	private String clazz;
	private String methodName;
	
	private Vector<Class> argumentclazzes;
	private Vector<String> argumentNames;
	private Vector<Object> arguments; 
	
	private Class returnClazz;
	private Object returnValue;
	
	private RemotingErrorException exception;
	
	public Message() {
		clazz = null;
		methodName = null;
		
		argumentclazzes = new Vector<Class>();
		argumentNames = new Vector<String>();
		arguments = new Vector<Object>();
		
		returnClazz = null;
		returnValue = null;
		
		exception = null;
	}
	
	public Message(String pClazz, String pMethodName,
			Vector<Class> pArgumentClazzes, Vector<String> pArgumentNames, Vector<Object> pArguments,
			Class pReturnClazz) {
		
		clazz = pClazz;
		methodName = pMethodName;
		
		argumentclazzes = pArgumentClazzes;
		argumentNames = pArgumentNames;
		arguments = pArguments;
		
		returnClazz = pReturnClazz;		
		
		returnValue = null;
		
		exception = null;
	}
	
	public Message(RemotingErrorException pException) {
		clazz = null;
		methodName = null;
		
		argumentclazzes = new Vector<Class>();
		argumentNames = new Vector<String>();
		arguments = new Vector<Object>();
		
		returnClazz = null;
		returnValue = null;		
		
		exception = pException;
	}
	
	public Vector<Class> getArgumentclazzes() {
		return argumentclazzes;
	}

	public void setArgumentclazzes(Vector<Class> argumentclazzes) {
		this.argumentclazzes = argumentclazzes;
	}

	public Vector<String> getArgumentNames() {
		return argumentNames;
	}

	public void setArgumentNames(Vector<String> argumentNames) {
		this.argumentNames = argumentNames;
	}

	public Vector<Object> getArguments() {
		return arguments;
	}

	public void setArguments(Vector<Object> arguments) {
		this.arguments = arguments;
	}

	public String getClazz() {
		return clazz;
	}

	public void setClazz(String clazz) {
		this.clazz = clazz;
	}

	public String getMethodName() {
		return methodName;
	}

	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}

	public Class getReturnClazz() {
		return returnClazz;
	}

	public void setReturnClazz(Class returnClazz) {
		this.returnClazz = returnClazz;
	}

	public Object getReturnValue() {
		return returnValue;
	}

	public void setReturnValue(Object returnValue) {
		this.returnValue = returnValue;
	}
	
	public String toString() {
		String returnString = "Dump of Marshaller Object:\n";

		if (clazz != null)
			returnString += "class:  " + clazz + "\n";
		if (methodName != null)
			returnString += "method: " + methodName + "\n";

		if (!argumentclazzes.isEmpty()) {
			returnString += "arguments:\n";
			for (int i = 0; i < argumentclazzes.size(); i++) {
				returnString += "\targclass: " + argumentclazzes.get(i).getName() + "\n" +
						        "\targname:  " + argumentNames.get(i) + "\n" +
						        "\targs:     " + arguments.get(i) + "\n";
			}
		}
		
		if (returnClazz != null)
			returnString += "returnClazz: " + returnClazz.getName() + "\n";
		if (returnValue != null)
			returnString += "returnValue: " + returnValue + "\n";
		
		if(exception != null)
			returnString += "exception: " + exception.toString() + "\n";
		
		return returnString;
	}

	public RemotingErrorException getException() {
		return exception;
	}

	public void setException(RemotingErrorException exception) {
		this.exception = exception;
	}
	
}